<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="dist/jquery/jquery-1.8.3.js"></script>
<LINK rel=stylesheet type=text/css href="../css/style.css">
<html>
<head>
    <title>发布信息</title>
</head>
<BODY>
<DIV id=header class=wrap>
    <DIV id=logo><IMG src="../images/logo.gif"></DIV></DIV>
<DIV id=regLogin class=wrap>
    <DIV class=dialog>
        <DL class=clearfix>
            <DT>新房屋信息发布</DT>
            <DD class=past>填写房屋信息</DD></DL>
        <DIV class=box>
            <FORM id=add_action method=post name=add.action
                  action=house!insertHouse.action>
                <DIV class=infos>
                    <TABLE class=field>
                        <TBODY>
                        <TR>
                            <TD class=field>标　　题：</TD>
                            <TD><INPUT id=add_action_title class=text type=text name=htitle> </TD></TR>
                        <TR>
                            <TD class=field>价　　格：</TD>
                            <TD><INPUT id=add_action_price class=text type=text name=hprice> </TD></TR>
                        <TR>
                            <TD class=field>面　　积：</TD>
                            <TD><INPUT id=add_action_floorage class=text type=text name=hfloorage></TD></TR>
                        <TR>
                            <TD class=field>房产证日期：</TD>
                            <TD><INPUT class=text type=text name=hpubdate></TD></TR>
                        <TR>
                            <TD class=field>联系方式：</TD>
                            <TD><INPUT id=add_action_contact class=text type=text name=hcontact> </TD></TR>
                        <TR>
                            <TD class=field>详细信息：</TD>
                            <TD><TEXTAREA name=hdesc></TEXTAREA></TD></TR>


                        <TR>
                            <TD class=field>户　　型：</TD>
                            <TD>
                                <SELECT class=text name=type.tid>
                                     <OPTION selected value=5>11一室一厅</OPTION>
                                     <OPTION selected value=6>22一室一厅</OPTION>
                                </SELECT>
                            </TD></TR>

                        <TR>
                            <TD class=field>位　　置：</TD>
                            <TD>区：<SELECT class=text name=district.did>
                                <%--<OPTION selected value=1004>海淀区</OPTION>--%>
                            </SELECT>
                                街：<SELECT class=text name=street.sid>
                                <%--<OPTION selected value=1001>中关村大街</OPTION>--%>
                                </SELECT> </TD></TR></TBODY></TABLE>

                    <DIV class=buttons><INPUT value=立即更新 type=submit>

                    </DIV></DIV></FORM></DIV></DIV></DIV>
<hr>
${requestScope.houseInfo}<br>
${requestScope.houseInfo.hid}<br>
${requestScope.houseInfo.htitle}<br>
${requestScope.houseInfo.hprice}<br>
${requestScope.houseInfo.type.tname}<br>
${requestScope.houseInfo.street.sname}<br>
<hr>
<DIV id=footer class=wrap>
    <DL>
        <DT>云和租房 © 2010 云和 京ICP证1000001号</DT>
        <DD>关于我们 · 联系方式 · 意见反馈 · 帮助中心</DD></DL></DIV></BODY></HTML>
<script type="text/javascript">


    /**
     * 调用setHouseInfo函数,对form表单进行填充
     */
    setHouseInfo();
    function setHouseInfo(){
        console.log('555调用setHouseInfo函数,对form表单进行填充');
        $("input[name=htitle]").attr('value','${requestScope.houseInfo.htitle}');
        $("input[name=hprice]").attr('value','${requestScope.houseInfo.hprice}');
        $("input[name=hfloorage]").attr('value','${requestScope.houseInfo.hfloorage}');
        $("input[name=hpubdate]").attr('value','${requestScope.houseInfo.hpubdate}');
        $("input[name=hcontact]").attr('value','${requestScope.houseInfo.hcontact}');
        $("TEXTAREA[name=hdesc]").attr('value','${requestScope.houseInfo.hdesc}');
        $("select[name='district.did']").attr('value','${requestScope.houseInfo.street.district.did}');
        $("select[name='street.sid']").attr('value','${requestScope.houseInfo.street.sid}');
        $("select[name='type.tid']").attr('value','${requestScope.houseInfo.type.tid}');

        $("select[name='type.tid'] option[value=${requestScope.houseInfo.type.tid}]").attr('selected','selected');
        $("select[name='type.tid'] option[value='6']").attr('selected','selected');

        console.log('传入参数核查=======START==========');
        console.log('$("input[name=htitle]").val()========'+'${requestScope.houseInfo.htitle}');
        console.log('$("select[name=hprice]").val()========'+'${requestScope.houseInfo.hprice}');
        console.log('$("input[name=hfloorage]").val()========'+'${requestScope.houseInfo.hfloorage}');
        console.log('$("input[name=hpubdate]").val()========'+'${requestScope.houseInfo.hpubdate}');
        console.log('$("input[name=hcontact]").val()========'+'${requestScope.houseInfo.hcontact}');
        console.log('$("input[name=hdesc]").val()========'+'${requestScope.houseInfo.hdesc}');
        console.log('$("select[name=district.did]").val()========'+'${requestScope.houseInfo.street.district.did}');
        console.log('$("select[name=district.did]").val()========'+$("select[name='district.did']").val());
        console.log('$("select[name=street.sid]").val()========'+$("select[name='street.sid']").val());
        console.log('$("select[name=type.tid] option[value=${requestScope.houseInfo.type.tid}]").val()========'+$("select[name='type.tid'] option[value=${requestScope.houseInfo.type.tid}]"));
        console.log($("select[name='type.tid'] option[value=${requestScope.houseInfo.type.tid}]"));
        console.log($("select[name='type.tid'] option"));
        console.log('传入参数核查========END=========');
    }



    /**
     * 房屋类型的下拉列表
     */
    selectType();
    function selectType(){
        $(function () {
            console.log('1111111');
            $.ajax({
                type:'post',
                url:'type!typeList.action',
                dataType:'json',
                success:function (data) {
                    var str1='';
                    $.each(data,function (index,obj) {
                        str1+='<option value='+obj.tid+'>'+obj.tname+'</option>';
                    });
                    $("select[name='type.tid']").append(str1);
                   /* console.log($("select[name='type.tid']").html());*/
                }
            });
        });
    }

    /**
     * 区县的下拉列表
     */
    selectDistrict();
    function  selectDistrict() {
        $(function () {
            console.log('2222222');
           $.ajax({
               type:'post',
               url:'district!districtList.action',
               dataType:'json',
               success:function (data) {
                   var str2='';
                   $.each(data,function (index,obj) {
                       str2+='<option value='+obj.did+'>'+obj.dname+obj.did+'</option>';
                   });
                   $("select[name='district.did']").append(str2);
                  /* console.log($("select[name='district.did']").html());*/
               }
           });
        });
    }

    /**
     * 街道的下拉列表
     */
    var did2str=-1;
    selectStreet();
    function selectStreet(){
        console.log('333333');
        console.log('333333====='+did2str);
        $(function () {
            $.ajax({
                type:'post',
                url:'street!streetList.action',
                data:{
                    sid:did2str/*实际是did,无法直接使用did的模型驱动*/
                },
                dataType:'json',
                success:function (data) {
                    var str3='';
                    $.each(data,function (index,obj) {
                        str3+='<option value='+obj.sid+'>'+obj.sname+obj.district.did+obj.district.dname+'</option>';
                        /*str3+='<option value='+obj.sid+'>'+obj.sname+'</option>';*/
                    });
                    $("select[name='street.sid']").empty();
                    $("select[name='street.sid']").append(str3);
                    /* console.log($("select[name='street.sid']").html());*/
                }
            });
        });
    }

    /*
        select-option的属性selected=selected
    * */

    $(function () {
        console.log('4444441111');
        $("select[name='district.did']").live('click',function () {
            console.log('44444422222');
            var did2val=$("select[name='district.did']").val();
            $("select[name='district.did'] option[value!="+did2val+"]").removeAttr('selected');
            $("select[name='district.did'] option[value="+did2val+"]").attr('selected','selected');
            did2str=$("select[name='district.did'] option[selected=selected]").val();
            selectStreet();
        });
    });






</script>


